package com.itcat.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.SmsHomeBrand;
import com.itcat.mysql.pojo.SmsHomeNewProduct;
import com.itcat.service.SmsHomeNewProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页新品管理
 */
@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {
    @Autowired
    private SmsHomeNewProductService homeNewProductService;


    //分页查询首页新品
    @GetMapping("/list")
    public CommonResult<CommonPage<SmsHomeNewProduct>> list(String productName,
                                                            Integer recommendStatus,
                                                            @RequestParam Integer pageSize,
                                                            @RequestParam Integer pageNum) {
        Page<SmsHomeNewProduct> homeNewProductList = homeNewProductService.list(productName, recommendStatus, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(homeNewProductList));
    }

    //添加新品
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeNewProduct> smsHomeNewProducts) {
        homeNewProductService.create(smsHomeNewProducts);
        return CommonResult.success();
    }

    //删除新品
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Integer> ids) {
        homeNewProductService.delete(ids);
        return CommonResult.success();
    }

    //修改是否推荐
    @PostMapping("/update/recommendStatus")
    public CommonResult updateRecommendStatus(@RequestParam List<Integer> ids,
                                              @RequestParam Integer recommendStatus) {
        homeNewProductService.updateRecommendStatus(ids, recommendStatus);
        return CommonResult.success();

    }

    //修改推荐品牌排序
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                   @RequestParam Integer sort) {
        homeNewProductService.updateSort(id, sort);
        return CommonResult.success();
    }
}
